/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package back;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import schoolMatSupport.IReader;

/**
 *
 * @author buben
 */
@ManagedBean(name = "viewer")
@SessionScoped
public class viewerBean {

    private int actualPage;
    private int actualZoom;
    private int actualHeight;
    private int actualTool;
    private boolean activeComments;
    
    @EJB
    IReader r;

    public int getActualPage() {
        return actualPage;
    }

    public void setActualPage(int actualPage) {
        this.actualPage = actualPage;
    }

    @PostConstruct
    public void init() {
        this.actualPage = 1;
        this.actualZoom = 96;
        this.actualHeight = 0;
        this.actualTool = 0;
        this.activeComments = false;
    }

    public void setActualTool(int actualTool) {
        this.actualTool = actualTool;
    }

    public int getActualTool() {
        return actualTool;
    }

    public boolean isActiveComments() {
        return activeComments;
    }

    public void setActiveComments(boolean activeComments) {
        this.activeComments = activeComments;
    }

    public void setActualHeight(int actualHeight) {
        this.actualHeight = actualHeight;
    }

    public int getActualHeight() {
        return actualHeight;
    }

    public int getActualZoom() {
        return actualZoom;
    }

    public void setActualZoom(int actualZoom) {
        this.actualZoom = actualZoom;
    }

    public void nextPage() {
        if (this.actualPage < r.getTotalPages()) {
            this.actualPage++;
        }
    }

    public void previousPage() {
        if (this.actualPage > 1) {
            this.actualPage--;
        }
    }

    public void gotoPage(int page) {
        this.actualPage = page;
    }

    public void zoomOut() {
        if (this.actualZoom > 20) {
            this.actualZoom -= 5;
        }
    }

    public void zoomIn() {
        if (this.actualZoom < 100) {
            this.actualZoom += 5;
        }
    }

    public int getZoomInPercent() {
        return (int) (this.actualZoom * 1.046667 );
    }

    public void restoreZoom() {
        this.actualZoom = 96;
    }

    public void fitToWindow() {
        this.actualZoom = 38;
    }

    public void turnOnNotes() {
        this.activeComments = true;

    }

    public void turnOffNotes() {
        this.activeComments = false;
    }

    public String styleButton(int tool) {
        if (this.actualTool == tool) {
            return "button_select";
        }
        return "button1";
    }

    public void activeSelectTool() {
        this.actualTool = 0;

    }

    public void activePinTool() {
        this.actualTool = 1;


    }

    public void activeAreaTool() {
        this.actualTool = 2;

    }
    
}
